package liuch.JMS.listener;

import javax.jms.*;

/**
 * @author 17101651
 * @ClassName DemoMessageListener
 * @Description 消息监听Messlistenter
 * @data 2018年08月18日
 */
public class DemoMessageListener implements MessageListener {
    @Override
    public void onMessage(Message message) {
        if (message instanceof ObjectMessage) {
            ObjectMessage objMessage = (ObjectMessage) message;
            try {
                Object obj = objMessage.getObject();
                System.out.println("接收到一个ObjectMessage，object=" + obj.toString());
            } catch (JMSException e) {
                e.printStackTrace();
            }
        } else if (message instanceof TextMessage) {
            try {
                TextMessage textMessage = (TextMessage) message;
                System.out.println("接收一个TextMessage:" + textMessage);
                System.out.println(textMessage.getText());
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }
}
